package com.idfsgm;

import java.util.HashMap;
import java.util.Map;

import com.example.idfsgm.R;

import datatypes.Assignment;
import datatypes.Duty;
import datatypes.DutyDate;
import datatypes.GuardDuty;
import datatypes.KitchenDuty;
import datatypes.Soldier;
import datatypes.Team;

import Utils.SavingAndLoadingCenter;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class AssigningScreen extends Activity {
	private ListView assignedSoldiersList;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.assigning_screen);

		assignedSoldiersList = (ListView) findViewById(R.id.assignedSoldiersList);

		// to retrieve object in second Activity
		Assignment ass = (Assignment) getIntent().getSerializableExtra(
				"Assignment");

		String[] assignedSoldierArray = new String[ass.getDutyMap().size()];

		StringBuilder assStr;
		int index = 0;
		if (ass != null) {

			for (Map.Entry<Soldier, Duty> entry : ass.getDutyMap().entrySet()) {
				assStr = new StringBuilder();
				Soldier s = entry.getKey();
				Duty d = entry.getValue();

				assStr.append("soldier " + s.getName() + " " + s.getLastName());
				assStr.append("\nassigned to ");

				if (d instanceof GuardDuty) {
					assStr.append("Guard Duty ");
				} else if (d instanceof KitchenDuty) {
					assStr.append("Kitchen Duty ");
				}

				assStr.append("at : \n");

				assStr.append(DutyDate.BuildReadableDate(d.getDate()
						.getStartingDate(), d.getDate().getEndingDate()));
				assignedSoldierArray[index++] = assStr.toString();

			}
		}

		assignedSoldiersList.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_multiple_choice,
				assignedSoldierArray));

	}
}